<?php
class User_Model_Menu 
{
 
	private $_table;
	//Initalizing Db Table  
	public function __construct(){
		$this->_table = new User_Model_DbTable_Menu();
	}
	
	/**
	*add One Row  
	*@param array $row 
	*@return boolean
	*/
	public function add($row){
		return $this->_table->insert($row);
	}
	
	/**
	*Update One Row  
	*@param rowSet $row Customer's data 
	*@param int $customer_id 
	*@return boolean
	*/
	public  function update($row,$id){	
		$where = $this->_table->getAdapter()->quoteInto('um_id = ?', $id); 
		return $this->_table->update($row, $where);		
	}

	/**
	*Get Rowset By ur_id
	*@param int $ur_id 职位ID
	*@return Rowset
	*/
	public function getByUmid($id){
		$select = $this->_table->select()->where('um_id = ?', $id);
		if($rowset=$this->_table->fetchRow($select)){
			return $rowset->toArray();
		}
	}
	
	/**
	*Get Rowset
	*@param 
	*@return Rowset
	*/
	public function getAllModule(){
		$select = $this->_table->select()
				->from('user_Menu', 'ur_module')
				->group('ur_module');
		$rowset = $this->_table->fetchAll($select);
		return $rowset;
	}
	
	/**
	 * 根据条件获取指定模块信息
	 */
	public function getByCond($cond,$type,$order='um_id',$count=20, $offset=0){
		$table = $this->_table->info('name');
		$select = $this->_table->select()->from($table, $type);
		if(isset($cond['um_title']) && $cond['um_title']){
			$select->where('um_title = ?',$cond['um_title']);
		}
		if('count(*)'==$type){
            return $this->_table->getAdapter()->fetchOne($select);
        }
        if ($count==0){        	
        	return $this->_table->fetchAll($select)->toArray(); 
        }
		$select->order($order);
		$select->limit($count,$offset);
		return $this->_table->fetchAll($select)->toArray();
	}
	
   /**
	*Delete One Row
	*@param int $ur_id
	*@return boolean
	*/
	public function delete($id){	
		$where = $this->_table->getAdapter()->quoteInto('um_id = ?', $id); 
		return $this->_table->delete($where);		
	}
	
	public function getAll(){
		$rowset = $this->_table->fetchAll();
		if($rowset){
			return $rowset->toArray();
		}		
	}
	
	
}